from langchain_text_splitters import RecursiveCharacterTextSplitter


def split_documents(documents, chunk_size=200, chunk_overlap=50):
    # 创建文本分割器对象
    text_splitter = RecursiveCharacterTextSplitter(
        chunk_size=chunk_size,
        chunk_overlap=chunk_overlap,
        length_function=len,  # 用于计算长度的函数
        separators=["\n\n", "\n", " ", ""]  # 分割时优先使用的分隔符

    )

    split_docs = text_splitter.split_documents(documents)
    return split_docs



